package com.blog.blogservice.config;

import com.blog.blogservice.domain.entity.MinIoConfigProperties;
import io.minio.MinioClient;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @author guanglin.ma
 * @date 2024-03-03 20:57
 */
@Component
@Configuration
public class MinioConfig {

    @Autowired
    private MinIoConfigProperties minIOConfigProperties;


    // 注册MinIO实例
    @Bean
    public MinioClient buildMinioClient() throws InvalidPortException, InvalidEndpointException {
        return new MinioClient(minIOConfigProperties.getEndpoint(),
                minIOConfigProperties.getAccessKey(),
                minIOConfigProperties.getSecretKey());
    }
}
